package com.bsdk.install.device.lockLora.v2.cmd;

/**
 * @projectName: lock
 * @package: com.hlslock.lock.cmd
 * @className: CMD8030
 * @author: HansYoung
 * @description: 通过密码或卡号删除
 * @date: 2023/12/6 14:16
 * @version: 1.0
 */
public class CMD8F30 extends CMD {

    public static class Builder extends CMD {

        private String num;
        private String fingerData;

        public Builder setUId(String uId) {
            this.uId = uId;
            return this;
        }

        public Builder setCMac(String cMac) {
            this.cMac = cMac;
            return this;
        }

        public Builder setDevId(String devId) {
            this.devId = devId;
            return this;
        }

        public Builder setCmd(String cmd) {
            this.cmd = cmd;
            return this;
        }

        public Builder setNum(Integer num) {
            this.num = String.format("%02d", num);
            return this;
        }

        public Builder setFingerData(String fingerData) {
            if (fingerData.length() < 200) {
                StringBuilder sb = new StringBuilder(fingerData);
                int leave = (200 - fingerData.length()) / 2;
                for (int i = 0; i < leave; i++) sb.append("00");
                this.fingerData = sb.toString();
            } else {
                this.fingerData = fingerData;
            }
            return this;
        }

        public CMD bulid() {
            StringBuilder data = new StringBuilder();
            data.append("02678F30" + this.num + this.fingerData);
            data.append("03");

            data.append(xor(data.toString()));

            return new CMD(uId, cMac, devId, cmd, data.toString());
        }
    }

    public static Builder getPushPayloadBuider() {
        return new Builder();
    }
}